﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kevin.Shop.Business.Core.Components;
using Kevin.Shop.Business.Products.Components;
using Kevin.Shop.Business.Service.Entity.Helper;
using RiderShop.Mobile.Common.Component;
using RiderShop.Mobile.ServiceEntity.Product;
using Kevin.Shop.Business.Core.Components.Responser;
using Kevin.Shop.Business.Service.Entity.SalesManagement.GiftCard;
using Kevin.Shop.Business.Service.Entity.SalesManagement.Enumerations;
using RiderShop.Mobile.ServiceEntity.Store;

namespace RiderShop.Mobile.Modle.MyAccount
{
    public class MyGiftCardModel
    {
        /// <summary>
        /// 用户的优惠券列表
        /// </summary>
        public List<GiftCardInfoExtend> GiftCardList { get; set; }

        /// <summary>
        /// 得到用户的优惠券列表
        /// </summary>
        /// <param name="status">status=0未使用|status=2已使用|status=4已过期</param>
        /// <param name="pageIndex">当前页的索引</param>
        /// <param name="pageSize">每页得到多少条</param>
        /// <returns>优惠券列表</returns>
        public DbQueryResult<List<GiftCardInfoExtend>> GetUserGiftCards(int status, int pageIndex, int pageSize)
        {
            string url = SiteUrl.FormatUrl("SalesManagement_GetGiftCardInfoByCustomerUserId");
            var query = new GiftCardInfoQuery()
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                CustomerUserId = 1100,
                Status = (GiftCardStatus)status
            };
            DbQueryResult<List<GiftCardInfoExtend>> result = RestfulHelper.Query<GiftCardInfoExtend>(url, query);
            if (result.Data.Count > 0)
            {
                Status = status;
                if (!string.IsNullOrEmpty(result.Tag))
                {
                    var list = result.Tag.Split(',');
                    NoUseCount = list.Length == 3 ? Convert.ToInt32(list[0]) : 0;//未使用优惠券数
                    TotalNoUsePage = (int)Math.Ceiling(NoUseCount / (double)pageSize);//未使用优惠券页数
                    UseCount = list.Length == 3 ? Convert.ToInt32(list[1]) : 0;//已使用优惠券数
                    TotalUsePage = (int)Math.Ceiling(UseCount / (double)pageSize);//已使用优惠券页数
                    ExpirationCount = list.Length == 3 ? Convert.ToInt32(list[2]) : 0;//已过期优惠券数
                    TotalExpirationPage = (int)Math.Ceiling(ExpirationCount / (double)pageSize);//已过期优惠券页数
                }
            }
            return result;
        }

        public int Status
        {
            get; 
            set;
        }

        //未使用的优惠券数
        private int _noUseCount = 0;
        public int NoUseCount
        {
            get { return _noUseCount; }
            set { _noUseCount = value; }
        }

        //已使用的优惠券数
        private int _useCount = 0;
        public int UseCount
        {
            get { return _useCount; }
            set { _useCount = value; }
        }

        //已过期的优惠券数
        private int _expirationCount = 0;
        public int ExpirationCount
        {
            get { return _expirationCount; }
            set { _expirationCount = value; }
        }

        //未使用优惠券总页数
        private int _totalNoUsePage;
        public int TotalNoUsePage
        {
            get { return _totalNoUsePage; }
            set { _totalNoUsePage = value; }
        }

        //已使用优惠券总页数
        private int _totalUsePage;
        public int TotalUsePage
        {
            get { return _totalUsePage; }
            set { _totalUsePage = value; }
        }

        //已过期优惠券总页数
        private int _totalExpirationPage;
        public int TotalExpirationPage
        {
            get { return _totalExpirationPage; }
            set { _totalExpirationPage = value; }
        }
    }
}
